package LeetCode.month02.day35;

public class No498 {
    public int[] findDiagonalOrder(int[][] mat) {
        int m = mat.length;
        int n = mat[0].length;
        int[] res = new int[m*n];
        int num = 0;
        for (int i = 0; i < m * n - 1; i++) {
            int minJ = Math.max(i-m+1,0);
            int maxJ = Math.min(n-1,i);
            if(i%2==0){
                for (int j = minJ; j <=maxJ ; j++) {
                    res[num++]=mat[i-j][j];
                }
            }else{
                for (int j = maxJ; j >= minJ; j--) {
                    res[num++]=mat[i-j][j];
                }
            }
        }
        return res;
    }
}
